﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using Utility;

public partial class Vehicle_Base_VehicleModity : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Request.QueryString["Type"] == null)
        {
            DetailsView1.ChangeMode(DetailsViewMode.Insert);
        }
        else if (Request.QueryString["Type"].ToString() == "View")
        {
            DetailsView1.ChangeMode(DetailsViewMode.ReadOnly);
        }
        else
        {
            DetailsView1.ChangeMode(DetailsViewMode.Edit);
        }

        if (!Page.IsPostBack)
        {
            if (DetailsView1.CurrentMode == DetailsViewMode.ReadOnly) return;
            PageCommonService.AddRequiredFieldValidator(DetailsView1, 1);
            //PageCommonService.AddRequiredFieldValidator(DetailsView1, 2);
            PageCommonService.AddRequiredFieldValidator(DetailsView1, 3);
            PageCommonService.AddRequiredFieldValidator(DetailsView1, 4);
            PageCommonService.AddRequiredFieldValidator(DetailsView1, 5);
            PageCommonService.AddRequiredFieldValidator(DetailsView1, 6);
            //PageCommonService.AddRequiredFieldValidator(DetailsView1, 7);
            //PageCommonService.AddRequiredFieldValidator(DetailsView1, 8);
        }


    }
    protected void VehicleSource_Updated(object sender, ObjectDataSourceStatusEventArgs e)
    {
        //Response.Redirect("VehicleMgr.aspx");
    }
    protected void ddl_PlanDate_DataBinding(object sender, EventArgs e)
    {
        //ListItem item = ((DropDownList)sender).Items.FindByValue("qqcrazyer");
        //if (item != null)
        //{
        //    item.Selected = true;
        //}
    }

    public static void SetSelectedValue(ListControl listcontrol, object value)
    {
        //ListItem item = listcontrol.Items.FindByValue(value.ToString());
        //if (item != null)
        //{
        //    listcontrol.Text = value.ToString();
        //}
        //else
        //{
        //    item = listcontrol.Items.FindByText(value.ToString());
        //    if (item != null)
        //        listcontrol.Text = value.ToString();
        //}

    }


    protected void DetailsView1_DataBound(object sender, EventArgs e)
    {
        //DropDownList dtp = (DropDownList)DetailsView1.FindControl("ddl_Organ");
        //dtp.Items.Insert(0, new ListItem("--请选择--", ""));
        ////string strParentId = this.DetailsView1.DataKeys[e.RowIndex]["OrganID"].ToString();
        ////dtp.SelectedValue = strParentId;

        //if (DetailsView1.CurrentMode == DetailsViewMode.Edit)
        //{
        //    //下拉菜单
        //    string filetitle = "";
        //    Label mylb = new Label();
        //    DropDownList mydl = new DropDownList();
        //    mylb = (Label)DetailsView1.FindControl("lab_Organ");
        //    mydl = (DropDownList)DetailsView1.FindControl("ddl_Organ");
        //    if (mylb != null && mydl != null)
        //    {
        //        filetitle = mylb.Text;
        //        ListItem myli = new ListItem();
        //        myli = mydl.Items.FindByValue(filetitle);
        //        if (myli == null)
        //        {
        //            ListItem myli2 = new ListItem(filetitle, filetitle);
        //            mydl.Items.Add(myli2);
        //            myli2.Selected = true;
        //        }
        //        else
        //        {
        //            myli.Selected = true;
        //        }
        //    }
        //}

    }
    protected void DetailsView1_ItemUpdating(object sender, DetailsViewUpdateEventArgs e)
    {
        //DropDownList mydl = (DropDownList)DetailsView1.FindControl("ddl_Organ");
        //if (mydl != null)
        //{
        //    e.NewValues["OrganID"] = mydl.Items[mydl.SelectedIndex].Value;
        //}



    }
    protected void DetailsView1_ItemInserting(object sender, DetailsViewInsertEventArgs e)
    {
        if (e.Values["OrganID"] == null)
        {
            e.Values["OrganID"] = Session["OrganID"].ToString();
        }
    }
}
